<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
</head>
<body>
<div id="app">
    <p>总数：{{total}}</p>
    <my-component
            @increase="handleGatTotal"
            @reduce="handleGatTotal"></my-component>
</div>
<script>
    Vue.component('my-component', {
        template:`<div>
                <button @click="handleIncrease" >+1</button>
                <button @click="handleReduce" :disabled="counter<=0">-1</button>
            </div>`,
        data() {
            return{
                counter:0
            }
        },
        methods:{
            handleIncrease(){
                this.counter++
                this.$emit('increase', this.counter)
            },
            handleReduce(){
                this.counter--
                this.$emit('reduce', this.counter)
            }
        }
    })
    var vm=new Vue({
        el:"#app",
        data:{
            total:0
        },
        methods:{
            handleGatTotal(total) {
                this.total=total
            }
        }
    })
</script>
</body>
</html>
